package dviz.tools;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.DisplayMode;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;

import dviz.visualSystem.impl.ProgressMonitor;

/**
 * @author  zxq071000
 */
public class Splash extends JFrame implements ProgressMonitor {

	private static final long serialVersionUID = 1L;
	/**
	 * @uml.property  name="jContentPane"
	 */
	private JPanel jContentPane = null;
	private JLabel helloSplash = null;
	/**
	 * @uml.property  name="progress"
	 */
	private JProgressBar progress = null;

	/**
	 * This method initializes progress
	 * @return  javax.swing.JProgressBar
	 * @uml.property  name="progress"
	 */
	private JProgressBar getProgress() {
		if (progress == null) {
			progress = new JProgressBar();
			progress.setPreferredSize(new Dimension(148, 34));
		}
		return progress;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Splash thisClass = new Splash();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */
	public Splash() {
		super();
		initialize();
		setVisible(true);
		DisplayMode mode = this.getGraphicsConfiguration().getDevice()
				.getDisplayMode();
		setLocation((mode.getWidth() - getWidth()) / 2,
				(mode.getHeight() - getHeight()) / 2);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 88);
		this.setContentPane(getJContentPane());
		this.setTitle("Loading..");
	}

	/**
	 * This method initializes jContentPane
	 * @return  javax.swing.JPanel
	 * @uml.property  name="jContentPane"
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			helloSplash = new JLabel();
			helloSplash.setText("Loading Project Resource...");
			helloSplash.setHorizontalAlignment(SwingConstants.CENTER);
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(helloSplash, BorderLayout.NORTH);
			jContentPane.add(getProgress(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	@Override
	public void setProgress(float p) {
		// TODO Auto-generated method stub
		progress.setValue((int) (p * 100));
		if(p==1.0f){
			setVisible(false);
		}
	}

} // @jve:decl-index=0:visual-constraint="10,10"
